package itsm.isperp.module.controller.project;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.framework.data.domain.PageResponse;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.dto.project.ProjectDomain;
import itsm.isperp.module.dto.project.ProjectDomain.ProjectDomainType;
import itsm.isperp.module.dto.project.ProjectMonitorDTO;
import itsm.isperp.module.service.app.AppRoleService;
import itsm.isperp.module.service.project.ProjProjectService;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 数据导入控制器
 * 
 * @author zhouhg
 * @date 2013-9-10
 */
@Controller
@RequestMapping("project/monitor")
public class ProjProjectMonitorController {

  @Autowired
  protected ProjProjectService projProjectService;

  /**
   * 根据分页器获取实体列表的json格式数据
   * 
   * @param request
   *          {@link JqGridRequest} jqGrid数据请求（查询条件、排序）
   * @param req
   *          {@link HttpServletRequest} http请求
   * @return json格式数据
   */
  @RequestMapping("list")
  @ResponseBody
  public PageResponse<ProjectMonitorDTO> list(JqGridRequest request,
      HttpServletRequest req) {
    
    /*request.setProjectDomain(ProjectDomain.newInstance("id",
        ProjectDomainType.Management));*/
    String  loginUserName=ContextHolder.getLoginUsername();
    String condition=" manager_id='"+loginUserName+"' or seller_id='"+loginUserName+"' or creator='"+loginUserName+"' or (EXISTS(SELECT 1 FROM proj_project_member WHERE proj_project_id=proj_project.id AND app_user_name='"+loginUserName+"'))";
    if(loginUserName.equals("admin"))
      condition="1=1";
    request.setSearchString(condition);
    
    return this.projProjectService.getProjectMonitorLists(request).toPage();

  }

  /**
   * 监控界面
   * 
   * @return 监控界面
   */
  @RequestMapping(value = "")
  public ModelAndView manage() {
    return new ModelAndView("project/monitor/manage");
  }

}
